package com.pomr.model.health;

import java.io.Serializable;
import java.util.Date;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import org.hibernate.annotations.Formula;
import org.hibernate.annotations.GenericGenerator;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.pomr.model.sys.Agency;
import com.pomr.model.sys.City;
import com.pomr.model.sys.Coutry;
import com.pomr.model.sys.Province;
import com.pomr.model.sys.User;
/**
 * 家庭档案 -- 机构共同管理 不属于任何机构（家庭中的成员档案不一定属于同一个机构）
 * @author Administrator
 *
 */
@Entity
@Table(name="family_record")
public class FamilyRecord implements Serializable{
	
	public User getUser() {
		return user;
	}
	public void setUser(User user) {
		this.user = user;
	}
	public String getUserName() {
		return userName;
	}
	public void setUserName(String userName) {
		this.userName = userName;
	}
	public Date getCreateTime() {
		return createTime;
	}
	public void setCreateTime(Date createTime) {
		this.createTime = createTime;
	}
	public Agency getAgency() {
		return agency;
	}
	public void setAgency(Agency agency) {
		this.agency = agency;
	}
	public String getAgencyName() {
		return agencyName;
	}
	public void setAgencyName(String agencyName) {
		this.agencyName = agencyName;
	}
	public Province getProvince() {
		return province;
	}
	public void setProvince(Province province) {
		this.province = province;
	}
	public String getProvinceName() {
		return provinceName;
	}
	public void setProvinceName(String provinceName) {
		this.provinceName = provinceName;
	}
	public City getCity() {
		return city;
	}
	public void setCity(City city) {
		this.city = city;
	}
	public String getCityName() {
		return cityName;
	}
	public void setCityName(String cityName) {
		this.cityName = cityName;
	}
	public Coutry getCoutry() {
		return coutry;
	}
	public void setCoutry(Coutry coutry) {
		this.coutry = coutry;
	}
	public String getCoutryName() {
		return coutryName;
	}
	public void setCoutryName(String coutryName) {
		this.coutryName = coutryName;
	}
	public String getHzName() {
		return hzName;
	}
	public void setHzName(String hzName) {
		this.hzName = hzName;
	}
	public Set<FamilyRelation> getFamilyRelations() {
		return familyRelations;
	}
	public void setFamilyRelations(Set<FamilyRelation> familyRelations) {
		this.familyRelations = familyRelations;
	}
	public Integer getId() {
		return id;
	}
	public void setId(Integer id) {
		this.id = id;
	}
	public String getAddr() {
		return addr;
	}
	public void setAddr(String addr) {
		this.addr = addr;
	}
	public String getTel() {
		return tel;
	}
	public void setTel(String tel) {
		this.tel = tel;
	}
	@Id
	@GeneratedValue(strategy = GenerationType.AUTO, generator = "native")
    @GenericGenerator(name = "native", strategy = "native")//AUTO 在mysql中需要指定使用本地策略生成主键值
	private Integer id;
	@Column(name="addr",length=200)
	private String addr;//家庭地址
	@Column(name="tel",length=20)
	private String tel;//家庭电话
	
	@OneToMany(fetch=FetchType.LAZY)
	@JoinColumn(name="familyrecord_id")
	private Set<FamilyRelation> familyRelations;//家庭关系 单向多对一 不维护关系
	
	@Formula("(select pr.name from person_record pr where pr.id = (select fr.personrecord_id from family_relation fr where fr.relation_id=1 and fr.familyrecord_id=id))")
	private String hzName;//户主名
	
	@ManyToOne(fetch=FetchType.LAZY)
	@JoinColumn(name="province_id") 
	private Province province;//省
	@Formula("(select pr.name from province pr where pr.id=province_id)")
	private String provinceName;//省名
	
	@ManyToOne(fetch=FetchType.LAZY)
	@JoinColumn(name="city_id") 
	private City city;//市
	@Formula("(select ci.name from city ci where ci.id=city_id)")
	private String cityName;//市名
	
	@ManyToOne(fetch=FetchType.LAZY)
	@JoinColumn(name="coutry_id") 
	private Coutry coutry;//县
	@Formula("(select c.name from coutry c where c.id=coutry_id)")
	private String coutryName;//县名
	
	@ManyToOne(fetch=FetchType.LAZY)
	@JoinColumn(name="createuser_id")
	private User user;//创建人
	@Formula("(select u.name from user u where u.id=createuser_id)")
	private String userName;
	@JsonFormat(locale="zh", timezone="GMT+8", pattern="yyyy-MM-dd HH:mm:ss")
	@Column(name="create_time")
	private Date createTime;//创建时间
	@ManyToOne(fetch=FetchType.LAZY)
	@JoinColumn(name="createagency_id")
	private Agency agency;//创建机构
	@Formula("(select a.name from agency a where a.id=createagency_id)")
	private String agencyName;

}
